package exams;

/**
 * Created by pc on 2015/5/15.
 */
public class JumpArray {
    public int solution (int [] A){
        int maxLen = 1;
        int nextIndex = A[0];
        while (nextIndex > -2 && nextIndex < A.length){
            //jump end
            if (nextIndex == -1) return maxLen;

            maxLen++;
            nextIndex = A[nextIndex];
//            System.out.println("max len is: " + maxLen + ", nextIndex: " + nextIndex);
        }
        return maxLen;
    }
    public static void main(String args[]){
        JumpArray ja = new JumpArray();

        System.out.println("max len is: " + ja.solution(new int[]{3, 2, 3, 4, 5}));
    }
}
